package Dat05;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;

public class Test01 {
    /**
     * 使用文件流复制myfile.txt文件为myfile_cp.txt
     * @author Admin
     *
     */
    public static void main(String[] args) {
        File f = new File("src/dat03/myfile.txt");
        File f2 = new File("src/Dat05/myfile_cp.txt");
        if(!f.exists()){
            try {
                f.createNewFile();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if(!f2.exists()){
            try {
                f2.createNewFile();
                FileInputStream fin = new FileInputStream(f);
                FileOutputStream fin1 = new FileOutputStream(f);
                FileOutputStream fout = new FileOutputStream(f2);
                Scanner in = new Scanner(System.in);
                System.out.println("请输入要复制的内容：");
                String str = in.nextLine();
                fin1.write(str.getBytes());
                System.out.println("写入成功");
                int len = -1;
                byte[] b = new byte[2048];
                while((len = fin.read(b)) != -1){
                    fout.write(b,0,len);
                }
                System.out.println("复制成功");

            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
